package com.phison.fenestrapro.dashboard.data;

import java.io.Serializable;
import java.util.Hashtable;

import com.phison.fenestrapro.dashboard.util.GlobalConstants;

/**
 *
 * 
 * @author Niall O'Hara
 *
 */
public class WindowShading implements Serializable, GlobalConstants {
	
	private static final long serialVersionUID = 1L;
	
	private Hashtable<String, Hashtable<Double, double[]>> tableSelector = new Hashtable<String, Hashtable<Double, double[]>>(6);
	private Hashtable<String, Integer> columnSelector = new Hashtable<String, Integer>(8);
	private Hashtable<String, Double> solarTransmittanceTable = new Hashtable<String, Double>(17);
	private	Hashtable<String, Double> shadingAngleTable = new Hashtable<String, Double>(8);
	private	Hashtable<Double, double[]> shadingFactorTypeA = new Hashtable<Double, double[]>(13);
	private Hashtable<Double, double[]> shadingFactorTypeB = new Hashtable<Double, double[]>(13);
	private Hashtable<Double, double[]> shadingFactorTypeC = new Hashtable<Double, double[]>(13);
	private Hashtable<Double, double[]> shadingFactorTypeD = new Hashtable<Double, double[]>(13);
	private Hashtable<Double, double[]> shadingFactorLightHorizLouvres = new Hashtable<Double, double[]>(7);
	private Hashtable<Double, double[]> shadingFactorDarkHorizLouvres = new Hashtable<Double, double[]>(7);
	
	/**
	 *
	 */
	public WindowShading() {
		
		tableSelector.put(A, shadingFactorTypeA);
		tableSelector.put(B, shadingFactorTypeB);
		tableSelector.put(C, shadingFactorTypeC);
		tableSelector.put(D, shadingFactorTypeD);
		tableSelector.put(LIGHT, shadingFactorLightHorizLouvres);
		tableSelector.put(DARK, shadingFactorDarkHorizLouvres);
		
		columnSelector.put(N, 0);
		columnSelector.put(NE, 1);
		columnSelector.put(NW, 1);
		columnSelector.put(E, 2);
		columnSelector.put(W, 2);
		columnSelector.put(SE, 3);
		columnSelector.put(SW, 3);
		columnSelector.put(S, 4);
		
		shadingAngleTable.put(SL_30, -30.0d);
		shadingAngleTable.put(SL_15, -15.0d);
		shadingAngleTable.put(SL0, 0.0d);
		shadingAngleTable.put(SL15, 15.0d);
		shadingAngleTable.put(SL30, 30.0d);
		shadingAngleTable.put(SL45, 45.0d);
		shadingAngleTable.put(SL60, 60.0d);
		
		solarTransmittanceTable.put(ST_DG_12_a_nc, 0.77d);
		solarTransmittanceTable.put(ST_DG_12_a_le_hc, 0.72d);
		solarTransmittanceTable.put(ST_DG_12_a_le_sc, 0.61d);
		solarTransmittanceTable.put(ST_DG_12_ar_le_sc, 0.64d);
		solarTransmittanceTable.put(ST_DG_16_a_nc, 0.76d);
		solarTransmittanceTable.put(ST_DG_16_a_le_sc, 0.64d);
		solarTransmittanceTable.put(ST_DG_16_ar_le_hc, 0.72d);
		solarTransmittanceTable.put(ST_DG_16_ar_le_sc, 0.62d);
		solarTransmittanceTable.put(ST_DG_16_ar_li_sc, 0.75d);
		solarTransmittanceTable.put(ST_DG_18_ar_le_sc, 0.67d);
		solarTransmittanceTable.put(ST_DG_16_ar_sc_le_sc, 0.336d);
		solarTransmittanceTable.put(ST_DG_16_ar_sc_cg, 0.37d);
		solarTransmittanceTable.put(ST_DG_16_ar_sc_sc, 0.18d);
		solarTransmittanceTable.put(ST_TG_12_ar_le_hc, 0.5d);
		solarTransmittanceTable.put(ST_TG_12_ar_le_sc, 0.5d);
		solarTransmittanceTable.put(ST_TG_16_ar_le_hc, 0.58d);
		solarTransmittanceTable.put(ST_TG_16_ar_le_sc, 0.5d);
		solarTransmittanceTable.put(ST_TG_12_k_le_sc, 0.42d);
		solarTransmittanceTable.put(ST_TG_12_k_li, 0.62d);
		
		shadingFactorTypeA.put(0.0, new double[] {1.000, 1.000, 1.000, 1.000, 1.000});
		shadingFactorTypeA.put(0.1, new double[] {0.960, 0.947, 0.938, 0.915, 0.884});
		shadingFactorTypeA.put(0.2, new double[] {0.919, 0.893, 0.875, 0.830, 0.767});
		shadingFactorTypeA.put(0.3, new double[] {0.883, 0.845, 0.818, 0.751, 0.656});
		shadingFactorTypeA.put(0.4, new double[] {0.846, 0.797, 0.760, 0.671, 0.545});
		shadingFactorTypeA.put(0.5, new double[] {0.816, 0.757, 0.711, 0.604, 0.464});
		shadingFactorTypeA.put(0.6, new double[] {0.785, 0.716, 0.661, 0.537, 0.382});
		shadingFactorTypeA.put(0.7, new double[] {0.760, 0.683, 0.620, 0.485, 0.353});
		shadingFactorTypeA.put(0.8, new double[] {0.734, 0.649, 0.579, 0.433, 0.324});
		shadingFactorTypeA.put(0.9, new double[] {0.713, 0.622, 0.546, 0.397, 0.313});
		shadingFactorTypeA.put(1.0, new double[] {0.692, 0.594, 0.512, 0.360, 0.301});
		shadingFactorTypeA.put(1.1, new double[] {0.675, 0.572, 0.486, 0.336, 0.293});
		shadingFactorTypeA.put(1.2, new double[] {0.657, 0.549, 0.459, 0.312, 0.285});
		
		shadingFactorTypeB.put(0.0, new double[] {1.000, 1.000, 1.000, 1.000, 1.000});
		shadingFactorTypeB.put(0.1, new double[] {0.964, 0.951, 0.940, 0.919, 0.890});
		shadingFactorTypeB.put(0.2, new double[] {0.928, 0.902, 0.880, 0.837, 0.780});
		shadingFactorTypeB.put(0.3, new double[] {0.903, 0.863, 0.828, 0.766, 0.686});
		shadingFactorTypeB.put(0.4, new double[] {0.877, 0.824, 0.776, 0.694, 0.592});
		shadingFactorTypeB.put(0.5, new double[] {0.859, 0.794, 0.733, 0.636, 0.526});
		shadingFactorTypeB.put(0.6, new double[] {0.841, 0.764, 0.689, 0.578, 0.459});
		shadingFactorTypeB.put(0.7, new double[] {0.829, 0.742, 0.654, 0.537, 0.437});
		shadingFactorTypeB.put(0.8, new double[] {0.816, 0.720, 0.619, 0.495, 0.414});
		shadingFactorTypeB.put(0.9, new double[] {0.807, 0.703, 0.591, 0.470, 0.406});
		shadingFactorTypeB.put(1.0, new double[] {0.798, 0.686, 0.563, 0.444, 0.398});
		shadingFactorTypeB.put(1.1, new double[] {0.791, 0.674, 0.541, 0.430, 0.393});
		shadingFactorTypeB.put(1.2, new double[] {0.784, 0.661, 0.519, 0.416, 0.388});
		
		shadingFactorTypeC.put(0.0, new double[] {1.000, 1.000, 1.000, 1.000, 1.000});
		shadingFactorTypeC.put(0.1, new double[] {0.969, 0.955, 0.943, 0.922, 0.897});
		shadingFactorTypeC.put(0.2, new double[] {0.937, 0.910, 0.885, 0.843, 0.794});
		shadingFactorTypeC.put(0.3, new double[] {0.919, 0.880, 0.839, 0.779, 0.715});
		shadingFactorTypeC.put(0.4, new double[] {0.900, 0.849, 0.792, 0.715, 0.636});
		shadingFactorTypeC.put(0.5, new double[] {0.889, 0.830, 0.755, 0.666, 0.584});
		shadingFactorTypeC.put(0.6, new double[] {0.877, 0.811, 0.717, 0.617, 0.531});
		shadingFactorTypeC.put(0.7, new double[] {0.869, 0.799, 0.688, 0.585, 0.514});
		shadingFactorTypeC.put(0.8, new double[] {0.861, 0.786, 0.658, 0.552, 0.497});
		shadingFactorTypeC.put(0.9, new double[] {0.856, 0.778, 0.635, 0.535, 0.492});
		shadingFactorTypeC.put(1.0, new double[] {0.850, 0.770, 0.611, 0.518, 0.486});
		shadingFactorTypeC.put(1.1, new double[] {0.846, 0.765, 0.593, 0.511, 0.483});
		shadingFactorTypeC.put(1.2, new double[] {0.842, 0.759, 0.574, 0.503, 0.479});
		
		shadingFactorTypeD.put(0.0, new double[] {1.000, 1.000, 1.000, 1.000, 1.000});
		shadingFactorTypeD.put(0.1, new double[] {0.975, 0.962, 0.948, 0.928, 0.897});
		shadingFactorTypeD.put(0.2, new double[] {0.949, 0.924, 0.895, 0.856, 0.794});
		shadingFactorTypeD.put(0.3, new double[] {0.938, 0.907, 0.858, 0.806, 0.715});
		shadingFactorTypeD.put(0.4, new double[] {0.926, 0.890, 0.821, 0.756, 0.636});
		shadingFactorTypeD.put(0.5, new double[] {0.919, 0.882, 0.794, 0.721, 0.584});
		shadingFactorTypeD.put(0.6, new double[] {0.912, 0.873, 0.767, 0.685, 0.531});
		shadingFactorTypeD.put(0.7, new double[] {0.908, 0.869, 0.747, 0.664, 0.514});
		shadingFactorTypeD.put(0.8, new double[] {0.903, 0.864, 0.727, 0.643, 0.497});
		shadingFactorTypeD.put(0.9, new double[] {0.900, 0.861, 0.711, 0.634, 0.492});
		shadingFactorTypeD.put(1.0, new double[] {0.897, 0.858, 0.694, 0.625, 0.486});
		shadingFactorTypeD.put(1.1, new double[] {0.895, 0.856, 0.682, 0.622, 0.483});
		shadingFactorTypeD.put(1.2, new double[] {0.892, 0.854, 0.669, 0.619, 0.479});
		
		shadingFactorLightHorizLouvres.put(-30d,	new double[] {0.573, 0.642, 0.680, 0.644, 0.471});
		shadingFactorLightHorizLouvres.put(-15d,	new double[] {0.635, 0.666, 0.660, 0.544, 0.408});
		shadingFactorLightHorizLouvres.put(0d,		new double[] {0.619, 0.598, 0.556, 0.434, 0.365});
		shadingFactorLightHorizLouvres.put(15d,		new double[] {0.547, 0.486, 0.431, 0.339, 0.315});
		shadingFactorLightHorizLouvres.put(30d,		new double[] {0.451, 0.373, 0.319, 0.264, 0.261});
		shadingFactorLightHorizLouvres.put(45d,		new double[] {0.340, 0.266, 0.223, 0.197, 0.199});
		shadingFactorLightHorizLouvres.put(60d,		new double[] {0.224, 0.168, 0.140, 0.129, 0.132});
		
		shadingFactorDarkHorizLouvres.put(-30d,	new double[] {0.491, 0.564, 0.602, 0.540, 0.302});
		shadingFactorDarkHorizLouvres.put(-15d,	new double[] {0.549, 0.580, 0.567, 0.414, 0.249});
		shadingFactorDarkHorizLouvres.put(0d,	new double[] {0.526, 0.500, 0.447, 0.298, 0.226});
		shadingFactorDarkHorizLouvres.put(15d,	new double[] {0.450, 0.380, 0.317, 0.212, 0.196});
		shadingFactorDarkHorizLouvres.put(30d,	new double[] {0.358, 0.273, 0.214, 0.157, 0.162});
		shadingFactorDarkHorizLouvres.put(45d,	new double[] {0.259, 0.181, 0.137, 0.114, 0.124});
		shadingFactorDarkHorizLouvres.put(60d,	new double[] {0.163, 0.107, 0.080, 0.074, 0.083});
		
	}
	
	/**
	 *
	 */
	public double getShadingFactor(String windowconfig, String orientation, double ratio) {
		Hashtable<Double, double[]> table = tableSelector.get(windowconfig);
		double[] values = table.get(ratio);
		double shadingFactor = values[columnSelector.get(orientation)];
		return shadingFactor;	
	}
	
	/**
	 *
	 */
	public double getSolarTransmittance(String glazingType) {
		double solarTransmittance = solarTransmittanceTable.get(glazingType);
		return solarTransmittance;	
	}
	
	/**
	 *
	 */
	public double getShadingAngle(String shadingAngleText) {
		double shadingAngle = shadingAngleTable.get(shadingAngleText);
		return shadingAngle;	
	}
	
}
